package com.huyanqi.core.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.xml.bind.annotation.adapters.XmlAdapter;
/**
 * 
 * <p>Title: JaxbDateSerializer.java</p>
 * 
 * <p>Description: 用来进行实体类Date属性注解</p>
 * 
 * <p>Datetime: 2012-1-4 上午11:49:02</p>
 *
 * @company 成都映潮科技有限公司
 * 
 * @author <a href="mailto:liwei@sunsharp.cn">p.k.ripper</a>
 *
 */
public class JaxbDateSerializer extends XmlAdapter<String, Date>{

    private SimpleDateFormat dateFormat = new SimpleDateFormat(Constants.DATE_TIME_PATTERN);
    
    @Override
    public String marshal(Date date) throws Exception {
    	if(null==date)return null;
    	return dateFormat.format(date);
    }

    @Override
    public Date unmarshal(String date) throws Exception {
    	if(null==date||"".equals(date))return null;
    	return dateFormat.parse(date);
    }

}
